<template>
	<view class="container">
		<c-cu-custom bgColor="bg-gradual-theme" >
			<block slot="content">惠活动</block>
		</c-cu-custom>
		
		<view class="margin-top-sm">
			<u-swiper :list="banber" :autoplay="false" height="160" :indicator="true"></u-swiper>
			
			<WaterfallsFlow :wfList='list' @itemTap="itemTap" />
		</view>
		
	</view>
</template>

<script>
	import WaterfallsFlow from '../../components/WaterfallsFlow/WaterfallsFlow.vue'
	import { getList } from "@/api/activity.js";
	export default {
		components: {
			WaterfallsFlow
		},
		data() {
			return {
				banber: [
					'https://cdn.pixabay.com/photo/2020/06/11/21/25/imp-5288348_960_720.jpg',
					'https://cdn.pixabay.com/photo/2020/06/11/21/25/imp-5288348_960_720.jpg',
					'https://cdn.pixabay.com/photo/2020/06/11/21/25/imp-5288348_960_720.jpg',
				],
				list: [],
				hasMore:true,
				page:0,
			}
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			// 触底刷新
			this.getList();
		},
		onPullDownRefresh() {
			// 上拉刷新
			this.page = 0;
			this.hasMore = true;
			this.list = [];
			this.getList();
		},
		methods: {
			getList(){
				var that = this;
				if(!that.hasMore) return;
				that.page++;
				getList({page:this.page}).then(res => {
					console.log(res);
					if(res.data.data.length < res.data.per_page){
						that.hasMore = false;
					}else{
						that.hasMore = true;
					}
					if(res.data.data.length > 0){
						that.list.push(...res.data.data)
					}
					console.log(that.list,that.hasMore );
					
				}).catch(err => {
					console.log(err);
				});
			},
			itemTap(item) {
				console.log(item);
				uni.navigateTo({
					url:"/pages/actives/detail?id="+item.id
				})
			}
		}

	}
</script>

<style lang="scss">
	.bg-gradual-theme {
		background-image: linear-gradient(45deg, $--theme-color, #f0f0f0);
		color: #ffffff;
	}
</style>